package com.qfedu.fmmall.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.qfedu.fmmall.common.vo.ResultVO;
import com.qfedu.fmmall.service.ProductCommentsService;
import com.qfedu.fmmall.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : yanBin
 * @date :2021/12/16 18:05
 */
@RestController
@CrossOrigin
@RequestMapping("/product")
@Api(value = "提供商品信息相关接口", tags = "商品管理")
public class ProductController {
    @Resource
    private ProductService productService;

    @Resource
    private ProductCommentsService productCommentsService;

    @GetMapping("/detail-info/{pid}")
    @ApiImplicitParam(dataType = "String", name = "pid", value = "商品id", required = true)
    @ApiOperation("商品基本信息查询")
    public ResultVO getProductBasicInfo(@PathVariable("pid") String pid) {
        return productService.getProductBasicInfo(pid);
    }


    @GetMapping("/detail-params/{pid}")
    @ApiImplicitParam(dataType = "String", name = "pid", value = "商品id", required = true)
    @ApiOperation("商品参数信息查询")
    public ResultVO getProductParamsById(@PathVariable("pid") String pid) {
        return productService.getProductParamsById(pid);
    }

    @GetMapping("/detail-comments/{pid}")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "pid", value = "商品id", required = true),
            @ApiImplicitParam(dataType = "int", name = "limit", value = "每一项条数", required = true),
            @ApiImplicitParam(dataType = "int", name = "pageNum", value = "当前页码", required = true)
    })

    @ApiOperation("商品评价信息查询")
    public ResultVO listCommentsByProductId(@PathVariable("pid") String pid, int limit, int pageNum) {
        return productCommentsService.listCommentsByProductId(pid, limit, pageNum);
    }

    @GetMapping("/detail-commentscount/{pid}")
    @ApiImplicitParam(dataType = "String", name = "pid", value = "商品id", required = true)
    @ApiOperation("商品评价统计查询")
    public ResultVO getProductCommentsCount(@PathVariable("pid") String pid) {
        return productCommentsService.getCommentsCountByProductId(pid);
    }

    @GetMapping("/listbycid/{cid}")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "cid", value = "商品分类id", required = true),
            @ApiImplicitParam(dataType = "int", name = "page", value = "页码", required = true),
            @ApiImplicitParam(dataType = "int", name = "size", value = "每一页条数", required = true)
    })
    @ApiOperation("商品三级分类Id查询商品分类")
    public ResultVO getProductByCategoryId(@PathVariable("cid") int cid, int page, int size) {
        return productService.getProductByCategoryId(cid, page, size);
    }

    @GetMapping("/listbrands/{cid}")
    @ApiImplicitParam(dataType = "int", name = "cid", value = "商品分类id", required = true)
    @ApiOperation("查询商品品牌")
    public ResultVO getBrandsByCategoryId(@PathVariable("cid") int cid) {
        return productService.listBrands(cid);
    }

    @GetMapping("/listbykeyword")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "keyword", value = "商品关键字", required = true),
            @ApiImplicitParam(dataType = "int", name = "page", value = "页码", required = true),
            @ApiImplicitParam(dataType = "int", name = "size", value = "每一页条数", required = true)
    })
    @ApiOperation("根据关键字查询商品")
    public ResultVO searchProducts(String keyword, int page, int size) {
        return productService.searchProduct(keyword, page, size);
    }

    @GetMapping("/listbrands-keyword")
    @ApiImplicitParam(dataType = "String", name = "keyword", value = "商品关键字", required = true)
    @ApiOperation("根据关键字查询商品品牌")
    public ResultVO getBrandsByKeyword(String keyword) {
        return productService.listBrandsByKeyword(keyword);
    }

}
